﻿namespace Sai.Core.Introspection
{
	using System;

	public class ObsoleteMarker 
	{
		public ObsoleteMarker()
			: this(false, string.Empty)
		{
		}

		public ObsoleteMarker(bool enabled)
			: this(enabled, string.Empty)
		{
		}

		public ObsoleteMarker(string reason)
			: this(!string.IsNullOrEmpty(reason), reason)
		{
		}

		public ObsoleteMarker(bool enabled, string reason)
		{
			this.IsEnabled = enabled;
			this.Reason = reason;
		}

		public bool IsEnabled { get; set; }

		public string Reason { get; set; }

		public override string ToString()
		{
			if (this.IsEnabled && !string.IsNullOrEmpty(this.Reason))
			{
				return string.Format("Obsolete because {0}", this.Reason);
			}

			return this.IsEnabled ? "Obsolete" : string.Empty;
		}

		public override int GetHashCode()
		{
			int hash = this.IsEnabled.GetHashCode();

			if (!string.IsNullOrEmpty(this.Reason))
			{
				hash ^= this.Reason.GetHashCode();
			}

			return hash;
		}
	}
}
